#!/usr/bin/perl
# log_properties.cgi
# Display Logfile Properties
require './naslog-lib.pl';

&ReadParse();

&header($text{'log_properties'},undef,"index",undef,0);

my $log=$in{'log'};
my $filename=$config{$log};
my $file_conf=$config{'file_conf'};
my $size=$in{'size'};
my $max =$in{'opt'};
if($max == 0 ) {
	$opt='truncate';
} else {
	$opt='archive';
}

$size=$size*1024;

if( ! -f $filename ) {
	&error($text{'log_cannotfind'});
}

my @fs=stat($filename);

if( ! -s $file_conf ) { 
	&error($text{'log_cannotstat'});
}
my $atime=localtime($fs[8]);
my $mtime=localtime($fs[9]);
my $ctime=localtime($fs[10]);

my ($f_name,$f_size,$f_opt,$f_max)=&get_conf_data($filename);

if ( $f_name ne $filename )  {
	&error($text{'log_cannotfind'});
}
if( defined $size && defined $opt && defined $max ) 
{
	my $changed=0;
	$changed=1 if ( $f_size != $size );
	$changed=1 if ( $f_max  != $max  );
	$changed=1 if ( $f_opt  ne $opt  );
	&save_conf_data($f_name,$size,$opt,$max) if($changed);
	($f_name,$f_size,$f_opt,$f_max)=&get_conf_data($filename);
}
$f_size=floor($f_size/1024);
print <<EOF;
<table class=mode1 border=0 width=100% align=center cellspacing=0 cellpadding=0>
    <tr class=mode1>
        <td><b>$text{'log_size'}:<b></td>
        <td> $fs[7] </td>
    </tr>
    <tr class=mode2>
        <td><b>$text{'log_atime'}:<b></td>
        <td> $atime </td>
    </tr>
    <tr class=mode1>
        <td><b>$text{'log_mtime'}:<b></td>
        <td> $mtime </td>
    </tr>
    <tr class=mode2>
        <td><b>$text{'log_ctime'}:<b></td>
        <td> $ctime  </td>
    </tr>
<form name=set method=post action=log_properties.cgi onsubmit='return onsubmit_form();'>

<input type=hidden name=log value='$log'>
<tr><td>&nbsp;</td></tr>
<tr>
<td><b>$text{'log_maxsize'}:</b></td>
<td>
<input class=text type=text size=18 name=size value=$f_size >
&nbsp;<b>K $text{'bytes'}</b>
</td>
</tr>
EOF

print "<tr>\n";
print "<td><b>$text{'log_option'}:</b></td>\n";
print "<td><select name=opt size=1 >\n";

my @olist=split(";",$text{'select'});

for ($i=0;$i<@olist;$i++){
	if($f_max == $i ) {
		print "<option value=$i selected>";
	} else {
		print "<option value=$i>";
	}
	print "$olist[$i]</option>\n";
}

print "</select></td>\n";
print "</tr>\n";

print <<EOF;
<tr><td>&nbsp;<td></tr>
<tr><td><input class=button1 name=setup type=submit value=$text{'submit'} ><td></tr>
</form>
</table>
<script>
function onsubmit_form()
{
	if( isNaN(document.forms[0].size.value) ) {
		alert("$text{'errorinput'}");
		return false;
	}
	if(document.forms[0].size.value <1 ) {
		alert("$text{'smallinput'}");
		return false;
	}
	if(document.forms[0].size.value>10000) {
		alert("$text{'biginput'}");
		return false;
	}
        document.forms[0].setup.disabled = true;
}
</script>
EOF


print "<hr>\n";
&footer("$log.cgi", $text{$log});

